home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / mac / PageMaker 6.5 SDK Mac / SourceCode / PageMakerClassLibrary / LowLevel / PReplyBuf.cpp < prev    next >
C/C++ Source or Header  |  1996-09-05  |  2KB  |  108 lines

  1. /*
  2.  *--- PReplyBuf.cpp -------------------------------------------------------
  3.  * Copyright (c) 1995-96 Adobe Systems Incorporated.  All rights reserved.
  4.  * Created on Thu, Oct 19, 1995 @ 8:18 PM by Paul Ferguson.
  5.  *
  6.  * Description:  For notes about this class, refer to the
  7.  * header file: PReplyBuf.h
  8.  *-------------------------------------------------------------------------
  9.  */
  10.  
  11. #include "string.h"
  12. #include "PReplyBuf.h"
  13.  
  14. PReplyBuf::PReplyBuf(const char * ch)
  15. {
  16.     bufStart = curCh = ch;
  17. }
  18.  
  19. PReplyBuf& PReplyBuf::operator>> (const char ** aStringRef)    // Just set char * and scan over the string.
  20. {
  21.     *aStringRef = (char *) curCh;
  22.     
  23.     register char * ch = (char *) curCh;
  24.     
  25.     while (*ch++)
  26.         ;
  27.  
  28.     if (long(ch) & 0x01) ++ch;
  29.     curCh = ch;
  30.  
  31.     return *this;
  32. }
  33.  
  34.  
  35. PReplyBuf& PReplyBuf::operator>> (char * aString)        // Copy the string.
  36. {
  37.     register char * dest = aString;
  38.     register const char * src = curCh;
  39.     
  40.     while (*dest++ = *src++)
  41.         ;
  42.  
  43.     if (long(src) & 0x01) ++src;
  44.     curCh = src;
  45.  
  46.     return *this;
  47. }
  48.  
  49. // This function copies and translates from C to Pascal string.
  50. // It will only copy a maximum of 255 characters, but will scan
  51. // to the end of the source string regardless of 
  52. PReplyBuf& PReplyBuf::operator>> (unsigned char * aString)        // Copy the Pascal string.
  53. {
  54.     register unsigned char * dest = aString;
  55.     unsigned char * byte0 = aString;
  56.     register const unsigned char * src = (const unsigned char *) curCh;
  57.     
  58.     register size_t numChars = 0;
  59.     
  60.     dest++;             // Reserve room for the length byte
  61.     while (*src)        // Copy string, but don't copy null byte.
  62.     {
  63.         *dest++ = *src++;
  64.         numChars++;
  65.     }
  66.  
  67.     src++;        // need to skip null byte;
  68.     if (long(src) & 0x01) ++src;
  69.     
  70.     if (numChars > 255) numChars = 255;
  71.     *byte0 = (unsigned char) numChars;
  72.     
  73.     curCh = (const char *) src;
  74.  
  75.     return *this;
  76. }
  77.  
  78. PReplyBuf& PReplyBuf::operator>> (short& aShort)
  79. {
  80.     aShort = *(short *) curCh;
  81.     curCh += sizeof(short);
  82.     return *this;
  83. }
  84.  
  85. PReplyBuf& PReplyBuf::operator>> (unsigned short& aShort)
  86. {
  87.     aShort = *(unsigned short *) curCh;
  88.     curCh += sizeof(unsigned short);
  89.     return *this;
  90. }
  91.  
  92. PReplyBuf& PReplyBuf::operator>> (long& aLong)
  93. {
  94.     aLong = *(long *) curCh;
  95.     curCh += sizeof(long);
  96.     return *this;
  97. }
  98.  
  99. PReplyBuf& PReplyBuf::operator>> (unsigned long& aLong)
  100. {
  101.     aLong = *(long *) curCh;
  102.     curCh += sizeof(unsigned long);
  103.     return *this;
  104. }
  105.  
  106.  
  107. // end of PReplyBuf.cpp
  108.